<#include "/common/layout.html"> 
<@layout title="123">
<script type="text/javascript" src="/js/easyui/easyui_grid.js"></script>
<script type="text/javascript">
var datagrid;
var model_name = "/order";
var model_title="订单";
	$(function() {
		
		$("#shop_id").combotree({    
		    url: '/shop/combotree/',  
		    multiple:true,
	    	editable:false,
		    width:200
		});
		
		$('#community_id').combobox({    
	    	url: '/community/combobox',   
		    valueField:'name',    
		    textField:'name',
		    editable:true,
		    width:150
	    });
		
		datagrid=$('#form_datagrid').datagrid({
		 	url:model_name+'/grid',
		 	columns:[[    
		        {field:'id',title:'编号',checkbox:true},
		        {field:'order_no',title:'订单编号',width:170,
		        	formatter:function(value,row,index){
			      		if(row.order_type=='PARENT'){
			      			return "<font color='red'>E</font>"+value;
			      		}else if(row.order_type=='SON'){
			      			return "<font color='red'>e</font>"+value;
			      		}else{
			      			return ""+value;
			      		}
					}
		        },
		        {field:'userName',title:'下单用户',width:80},
		        {field:'userPhone',title:'用户手机号',width:100},
		        {field:'shopName',title:'供应商',width:100},
		        {field:'community_name',title:'服务站',width:100},
		        {field:'receipt_name',title:'收货人',width:80},
		        {field:'agent_fee',title:'代购费',width:50},
		        {field:'amount',title:'订单金额(元)',width:80},
		        {field:'pay_amount',title:'实付金额(元)',width:80},
		        {field:'status',title:'状态',width:70,
		        	formatter:function(value,row,index){
			      		if(row.status=='MERCHANT_UNCONFIRMED'){
			      			return "<font color='red'>待商户确认</font>";
			      		}else if(row.status=='USER_UNPAYMENT'){
			      			return "<font color='#852456'>待用户支付</font>";
			      		}else if(row.status=='MERCHANT_UNDELIVERY'){
			      			return "<font color='blue'>待商户发货</font>";
			      		}else if(row.status=='USER_UNRECEIPT'){
			      			return "待用户收货";
			      		}else if(row.status=='COMPLETED'){
			      			return "已完成";
			      		}else if(row.status=='MERCHANT_RETURN'){
			      			return "<font color='#000333'>已退款</font>";
			      		}
			      		else if(row.status=='CANCEL'){
			      			return "<font color='#000333'>已取消</font>";
			      		}
					}
		        },
		        {field:'pay_time',title:'支付时间',width:130},
		        {field:'created_time',title:'订单时间',width:130},
		        {field:'idValue',title:'操作',
			        formatter:function(value,row,index){
			        	var restr="";
			        	<#if session.current_admin?? && session.current_admin.role_ids?? && session.current_admin.role_ids=='6' && row.order_type!='PARENT'>
						<#else>
			        	restr="<a href='#' onclick='refund("+row.id+")'  class='linkbutton' icon='icon-reload' >退款</a>&nbsp;";
						</#if>
			        	
			        	var otherStr = "";
			        	if(row.status=='MERCHANT_UNDELIVERY' && row.order_type!='PARENT'){
			        		otherStr = "<a href='#' onclick='audit("+row.id+",\"USER_UNRECEIPT\")'  class='linkbutton' icon='icon-reload' >发货</a>";
			        		return restr + otherStr;
			        	}
			        	if(row.status=='USER_UNRECEIPT' && row.order_type!='PARENT'){
			        		otherStr = "<a href='#' onclick='audit("+row.id+",\"COMPLETED\")'  class='linkbutton' icon='icon-reload' >结单</a>";
			        		return otherStr;
			        	}
			        	
			        	
			        }
		        }
		    ]],
		    toolbar : "#order_toolbar",
			onLoadSuccess:function(data){
				$(".linkbutton").linkbutton();
			}
		})
	})
	
	function audit(id_,status) {
		var audit_url= model_name+"/audit/"+id_;
		if(status) audit_url+="-"+status;
		$.messager.confirm('请确认', '确认操作？', function(r) {
			if (r) {
				$.ajax({
					url : audit_url,
					dataType : 'json',
					success : function(r) {
						datagrid.datagrid('load');
						datagrid.datagrid('unselectAll');
						if (r.success) {
							$.messager.show({
								msg:r.msg,
								title:'提示'
							});
							editRow = undefined;
						} else {
							$.messager.alert("操作错误",r.msg,'error');
						}
					}
				});
			}
		});
	}
	
	function refund(id_) {
		var refund_url= "/wx/refund/"+id_;
		//var refund_url= "/wx/refund/"+id_+"-"+refundFee;
		$.messager.confirm('请确认', '确认操作？', function(r) {
			if (r) {
				$.ajax({
					url : refund_url,
					dataType : 'json',
					success : function(r) {
						datagrid.datagrid('load');
						datagrid.datagrid('unselectAll');
						if (r.success) {
							$.messager.show({
								msg:r.msg,
								title:'提示'
							});
							editRow = undefined;
						} else {
							$.messager.alert("操作错误",r.msg,'error');
						}
					}
				});
			}
		});
	}
	
	function exportExcel(){
        //var exportForm=$("#searchForm").serialize();
        var exportForm = document.getElementById('searchForm');
        //$.post("/order/excelExport", form, function (result) {}, "text");
		exportForm.action="/order/excelExport";
		exportForm.submit();
	}
	
	//采购报表
	function exportFurchaseReport(){
        var exportForm = document.getElementById('searchForm');
		exportForm.action="/order/exportFurchaseReport";
		exportForm.submit();
	}
	
	//分拣报表
	function exportSortingReport(){
        var exportForm = document.getElementById('searchForm');
		exportForm.action="/order/exportSortingReport";
		exportForm.submit();
	}
	
	//订单商品汇总
	function exportProductCountReport(){
        var exportForm = document.getElementById('searchForm');
		exportForm.action="/order/exportProductCountReport";
		exportForm.submit();
	}
	
	//订单商品明细
	function exportOrderProductDetailReport(){
        var exportForm = document.getElementById('searchForm');
		exportForm.action="/order/exportOrderProductDetailReport";
		exportForm.submit();
	}
	
	//批量发货
	function batchOperator(status) {
		var rows = datagrid.datagrid('getSelections');
		var ids = [];
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要对当前所选订单发货？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : model_name+"/batchOperator",
						data : {
							ids : ids.join(','),
							status : status
						},
						dataType : 'json',
						success : function(r) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							if (r.success) {
								$.messager.show({
									msg:r.msg,
									title:'提示'
								});
								editRow = undefined;
							} else {
								$.messager.alert("操作错误",r.msg,'error');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要'+tipStr+'的商品！', 'error');
		}
	}
</script>
<script type="text/javascript" src="/js/easyui/easyui_grid_common.js"></script>

</head>
<body  class="easyui-layout">
<div id="imgShow"  style="position: absolute;display:none;border: 4px #ccc solid ;z-index:10;background-color:#fff;padding:5px;">
<img src="" width="150px">
</div>
<div region="north" border="false" title="搜索" collapsed="false"
		style="height: 92px; overflow:hidden;" align="left">
	<div class="tableForm datagrid-toolbar" >
	<form id="searchForm">
		<table style="height: 100%;width:auto;">
			<tr>
				<!-- <td>订单编号</td>
				<td><input type="text" name="LIKE_o.id" style="width:148px;"></td> -->
				<td>订单状态</td>
				<td>
					<select id="status" class="easyui-combobox" name="EQ_o.status" style="width:150px;">   
					    <option value="">请选择</option>
					    <option value="MERCHANT_UNCONFIRMED">待商户确认</option>   
					    <option value="USER_UNPAYMENT">待用户支付</option>   
					    <option value="MERCHANT_UNDELIVERY">待商户发货</option>
					    <option value="USER_UNRECEIPT">待用户收货</option>   
					    <option value="COMPLETED">已完成</option> 
					    <option value="MERCHANT_RETURN">已退款</option>
					    <option value="CANCEL">已取消</option>
					</select>  
				</td>
				<td>订单号</td>
				<td colspan="3"><input type="text" name="EQ_o.id">
				&nbsp;&nbsp;
				<#if session.current_admin?? && session.current_admin.role_ids?? && session.current_admin.role_ids=='6'>
				<#else>
				商铺名称&nbsp;<input id="shop_id" name="IN_o.shop_id"/>
				&nbsp;&nbsp;
				</#if>
				社区服务站&nbsp;<input id="community_id" type="text" name="LIKE_o.community_name">
				<!-- <input id="community_id" type="text" name="EQ_o.community_id"> -->
					<!-- ${session.current_admin.name} -->
				</td>
			</tr>
			<tr>
				<td>用户手机号</td>
				<td><input type="text" name="EQ_u.phone"></td>
				<td>下单时间</td>
				<td>
				<input name="GE_o.created_time"class="easyui-datetimebox" >-<input name="LE_o.created_time"class="easyui-datetimebox" > 
				</td>
				<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="_search();">查询</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">取消</a>
				<!-- <a href="javascript:void(0);" class="easyui-linkbutton" onclick="exportExcel();">导出Excel</a> -->
				&nbsp;&nbsp;&nbsp;
				[<a href="javascript:exportExcel();"><font style="font-size: 13px;font-weight: bolder;"> 导出订单Excel </font></a>]
				&nbsp;&nbsp;&nbsp;
				[<a href="javascript:exportFurchaseReport();"><font style="font-size: 13px;font-weight: bolder;"> 采购报表 </font></a>]
				&nbsp;&nbsp;&nbsp;
				[<a href="javascript:exportSortingReport();"><font style="font-size: 13px;font-weight: bolder;"> 分拣清单 </font></a>]
				&nbsp;&nbsp;&nbsp;
				[<a href="javascript:exportProductCountReport();"><font style="font-size: 13px;font-weight: bolder;"> 订单商品汇总 </font></a>]
				&nbsp;&nbsp;&nbsp;
				[<a href="javascript:exportOrderProductDetailReport();"><font style="font-size: 13px;font-weight: bolder;"> 商品明细 </font></a>]
				</td>
			</tr>
		</table>
	</form>
	</div>
</div>
<div region="center" border="false">
	<table  id="form_datagrid" >   
	</table>
</div>
<div id="Dialog_"></div>
<div id="order_toolbar">
<script type="text/javascript">
//查看
function orderView(id_,title){
	if(id_==undefined){
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			id_=rows[0].id;
		}else{
			$.messager.alert('提示', '请选择一条记录！', 'error');
			return;
		}
		orderOoip(model_name+"/view/"+id_,title);
	}
}
function orderOoip(url,title){
	$.messager.progress({text:'数据加载中....',interval:100});
	$('#Dialog_').dialog({
	    title: '查看-'+model_title,   
	    width: 810,   
	    height: 500,
	    top:0, 
	    cache: false,
	    maximizable:true,
	    href: url,   
	    modal: true,
	    onLoad:function(){
	    	$.messager.progress('close');
	    },
	    onLoadError:function(){
	    	$.messager.progress('close');
	    },
		buttons:[{
			text:"关闭",
			handler:function() {
				$('#Dialog_').dialog('close');
			}
		}]
	});
}
</script>



<a href="javascript:void(0)" id="grid_toolbar_view" onclick="orderView();" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true">查看</a>
<a href="javascript:void(0)"  onclick="datagrid.datagrid('reload');" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
<a href="javascript:void(0)"  onclick="datagrid.datagrid('clearSelections');" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">取消选中</a>

<a href="javascript:void(0);" class="easyui-linkbutton" onclick="batchOperator('USER_UNRECEIPT');">批量发货</a>
</div>
</body>
</@layout>